package czk.concrent.threadpool.exceptiondeal;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author:ChenZhangKun
 * @Date: 2022/12/6 21:02
 */
public class ThreadPoolExecutorManage {
    // 线程池异常的全局处理
    public static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            5,
            5,
            10L,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(10),
            new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    // 全局处理异常
                    t.setUncaughtExceptionHandler((t1, e) -> {
                        // 处理异常
                        System.out.println("异常被处理了");
                    });
                    return t;
                }
            }
    );
}
